package com.lbc.controller;

import com.lbc.bean.dto.ScrollerDTO;
import com.lbc.bean.dto.ScrollerModifyDTO;
import com.lbc.bean.vo.ScrollerVO;
import com.lbc.common.resp.ResponseResult;
import com.lbc.service.ScrollerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author xyl
 * @date 2021-03-16 20:32
 */
@Api(tags = "轮播图接口")
@RestController
@RequestMapping("scroller")
public class ScrollerController {

    @Autowired
    private ScrollerService scrollerService;

    @RequiresRoles("admin")
    @ApiOperation("添加后 , 默认为启用状态")
    @PostMapping("add")
    public ResponseResult add(@RequestBody @Validated ScrollerDTO scrollerDTO){
        return ResponseResult.toResponse(scrollerService.add(scrollerDTO));
    }

    @RequiresRoles("admin")
    @ApiOperation("修改轮播图")
    @PutMapping("modify")
    public ResponseResult modify(@RequestBody @Validated ScrollerModifyDTO scrollerModifyDTO){
        return ResponseResult.toResponse(scrollerService.modify(scrollerModifyDTO));
    }

    @RequiresRoles("admin")
    @ApiOperation("删除轮播图")
    @DeleteMapping("/remove/{scrollerId}")
    public ResponseResult remove(@PathVariable Integer scrollerId){
        return ResponseResult.toResponse(scrollerService.remove(scrollerId));
    }

    @ApiOperation("轮播图列表")
    @ApiImplicitParam(name = "state",value = "0停用  1启用",paramType = "query",dataType = "int")
    @GetMapping("list")
    public ResponseResult<List<ScrollerVO>> list(@RequestParam(required = false) Integer state){
        return new ResponseResult<>(scrollerService.list(state));
    }
}
